/**
 * 添加日志服务
 */
const env = process.env.NODE_ENV; // 环境变量参数
console.log('env===>', env);

// 日志
const fs = require('fs');
const path = require('path');

// 写日志
function writeLog(writeStream, log) {
    writeStream.write(log + '\n'); // 关键代码
}

/**
 * 创建水桶
 * @param {*} fileName 
 * @returns 
 */
function createWriteStream(fileName) {
    const fullFileName = path.join(__dirname, '../', '../', 'logs', fileName);
    const writeStream = fs.createWriteStream(fullFileName, {
        flags: 'a' // 追加内容
    });
    return writeStream;
}

/**
 * 
 */
const accesswriteStream = createWriteStream('access.log');


function access(log) {
    if(env !== 'production') {
        writeLog(accesswriteStream, log);
    } else {
        console.log('logs===>', log)
    }
    
}
 
module.exports = {
    access
}